from django.shortcuts import render
from django.http import HttpResponse
from .models import MyFile, MyImage
from django.views import View


# Create your views here.

def file(request):
    return render(request, 'imagefile/file.html')


def uploadfile(request):
    if request.POST:
        file = request.FILES.get('myfile')
        print(file)
        MyFile.objects.create(file=file)
        return HttpResponse('上传成功')
    else:
        return HttpResponse('没有可以上传的文件')


class ImageView(View):
    def get(self, request):
        return render(request, 'imagefile/image.html')

    def post(self, request):
        image = request.FILES.get('myimage')
        MyImage.objects.create(image=image)
        return HttpResponse('上传图片成功')
